<?php
/**
 * Yabsta News
 *
 * News Model Class
 * 
 * This file is a subject under proprietary sofrware license
 * 
 * @category
 * @package
 * @subpackage
 * @author      valerii lazarevych <lazarevuch@gmail.com>
 * @copyright   Copyright(c) Valerii Lazarevych
 * @license     proprietary software license
 * @version     $Id: News.php 28.05.2012 21:04:05 valerii $
 */

/**
 * Class News Model
 */
class models_News extends Model
{    
    /**
     * Get news list
     * 
     * @return array of News objects 
     */
    public function newsList()
    {
       return $this->select()->order('id','desc')->execute();
    }
    
    /**
     * News filtring by tags
     * 
     * @param string $tags
     * @return array of News objs
     */
    public function newsFiltringByTags(array $tags)
    {
        $this->select();
        
        foreach ($tags as $tag) {
            $this->where("tags like '%".trim($tag)."%' and");       }            
        $this->where('1');
                
        return $this->order('id', 'desc')->execute();
    }
    
    /**
     * News search by body text
     * 
     * @param string $searchStr
     * @return array of News objs
     */
    public function newsLooking(array $searchStr)
    {
        $this->select();
        
        foreach ($searchStr as $word) {
            $this->where("title like '%".trim($word)."%' and ");        }
        $this->where('1');       
                
        return $this->order('id', 'desc')->execute();        
    }
}
